//
//  ImageCollectionViewCell.m
//  Diary
//
//  Created by lanou3g on 15/12/22.
//  Copyright © 2015年 lanou3g. All rights reserved.
//

#import "ImageCollectionViewCell.h"

@implementation ImageCollectionViewCell


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self allViews];
    }
    return self;
}

//添加子视图
- (void)allViews{
    
    self.imageView = [[UIImageView alloc] initWithFrame:self.contentView.bounds];
    [self.contentView addSubview:self.imageView];
    ///注册通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(beginEdit) name:@"tongzhi" object:nil];
    
}
//实现通知方法
-(void)beginEdit{
    UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(10, 10, 30, 30)];
    //button.backgroundColor  = [UIColor redColor];
    [button setBackgroundImage:[UIImage imageNamed:@"未选中.jpg"] forState:UIControlStateNormal];
    
    [button addTarget:self action:@selector(SelectButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.contentView addSubview:button];
    NSLog(@"1111111");
}

//bounds发生改变时
- (void)layoutSubviews{
    [super layoutSubviews];
    self.contentView.frame = self.contentView.bounds;
    
}


#pragma mark -- button 点击事件
-(void)SelectButtonAction:(UIButton *)sender{
    if (!sender.selected) {
        [sender setBackgroundImage:[UIImage imageNamed:@"选中.jpg"] forState:UIControlStateNormal];
        
     
        
   sender.selected = YES;
    }else{
         [sender setBackgroundImage:[UIImage imageNamed:@"未选中.jpg"] forState:UIControlStateNormal];
        sender.selected = NO;
    }
    
    
    
    
}



@end
